﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MAT.Model;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Windows.Forms;
namespace MAT.Controllers
{
    class ctrReportSupplier
    {
        private frmReportSupplier _frmReportSupplier = null;

        public frmReportSupplier FrmReportSupplier
        {
            get { return _frmReportSupplier; }
            set { _frmReportSupplier = value; }
        }
        MAT_Context context = new MAT_Context();
        CommonClass ccl = new CommonClass();
        private bool check(TextBox tb)
        {
            foreach (SUPPLIER supplier in context.SUPPLIERs.ToList())
            {
                if (tb.Text == supplier.SUPPLIER_NAME)
                    return true;
            }
            MessageBox.Show("Supplier is wrong!");
            tb.Text = "";
            tb.Focus();
            return false;
        }

        //ReportDocument cryRpt;
        public void btnReportSupplier_Click()
        {
            if (check(_frmReportSupplier.textBox1))
            {
                ReportDocument cryRpt = new ReportDocument();
                cryRpt.Load(Application.StartupPath + @"\..\..\Reports\crpReportSupplier.rpt");

                ccl.automationConnect(cryRpt);
                ccl.report_Parameter(cryRpt, _frmReportSupplier.textBox1.Text, "SupplierName");
                _frmReportSupplier.crystalReportViewer1.ReportSource = cryRpt;
                _frmReportSupplier.crystalReportViewer1.Refresh();
            }
        }

        public void btnReportAllSupplier_Click()
        {
            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load(Application.StartupPath + @"\..\..\Reports\crpReportAllSupplier.rpt");
            ccl.automationConnect(cryRpt);
            _frmReportSupplier.crystalReportViewer1.ReportSource = cryRpt;
            _frmReportSupplier.crystalReportViewer1.Refresh();
        }
        public void btnExport()
        {
            _frmReportSupplier.crystalReportViewer1.ExportReport();
        }
        public void btnPrint()
        {
            _frmReportSupplier.crystalReportViewer1.PrintReport();
        }

    }
}
